home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
034a
/
trunclog.zip
/
TRUNCLOG.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1991-01-13
|
3KB
|
88 lines
Program TruncLog; {FrontDoor LOG-file truncator}
{SYNTAX: trunclog <logfile> <days to keep (max 255)> [<keepfile>]}
{Written by Erik Wachtmeester, 10-jan-1991 in Turbo Pascal (tm) 5.5}
uses Dos;
type DateStr = string[9];
Str127 = string[127];
const MonthName: array [1..12] of string[3] =
('Jan','Feb','Mar','Apr','May','Jun',
'Jul','Aug','Sep','Oct','Nov','Dec');
var DateNr: longint;
Year, Month, Day, DOW: word;
KeepDays: byte;
Dummy: integer;
LogName, KeepName, Line: string[80];
KeepLog, Keep: boolean;
Infile, Outfile, Keepfile: text;
function DateConv(Nyear,Nmonth,Nday: word): longint;
begin
DateConv := trunc(365.25*Nyear)+trunc(30.6*Nmonth)+Nday
-(Nyear div 100)+(Nyear div 400)-723241; {01-jan-1980 = 1}
end;
function GetDNum(Line: string): longint;
var Gyear, Gmonth, Gday: word;
I: byte;
CLine: ^Str127;
begin
CLine := Ptr(PrefixSeg, $80); { "abuse" TP's parameter parsing to }
CLine^ := Line; { extract the date from the log entry. }
val(copy(ParamStr(5),1,2),Gyear,Dummy);
Gyear := Gyear+1900;
Gmonth := 0;
for I := 1 to 12 do
if ParamStr(4)=MonthName[I] then Gmonth := I;
val(ParamStr(3),Gday,Dummy);
GetDNum := DateConv(Gyear,Gmonth,Gday);
end;
begin
writeln;
writeln('*** TRUNCLOG FrontDoor log file truncator, by Erik Wachtmeester ***');
if length(ParamStr(1))>0 then LogName := ParamStr(1);
if length(ParamStr(2))>0 then val(ParamStr(2),KeepDays,Dummy);
Keep := False;
if length(ParamStr(3))>0 then begin
KeepName := ParamStr(3);
assign(KeepFile,KeepName);
{$I-} reset(KeepFile); {$I+}
if ioresult=0 then begin
close(KeepFile);
append(KeepFile);
end else rewrite(KeepFile);
Keep := True;
end;
assign(Infile,LogName);
{$I-} reset(Infile); {$I+}
if ioresult+Dummy<>0 then begin
writeln;
writeln(^G,'*** TRUNCLOG error! ***');
writeln(' Syntax: TRUNCLOG <logfile> <days to keep (max. 255)> [<keepfile>]');
writeln(' <logfile> will be truncated as of today minus <days to keep>,');
writeln(' and all older lines will be written to <keepfile> (optional).');
writeln;
halt(1);
end;
GetDate(Year,Month,Day,DOW);
DateNr := DateConv(Year,Month,Day)-KeepDays;
KeepLog := False;
assign(Outfile,'TRUNCLOG.$$$');
rewrite(Outfile);
while not eof(Infile) do begin
readln(Infile,Line);
if not KeepLog then
if copy(Line,1,10)='----------' then
if GetDNum(Line)>=DateNr then KeepLog := True;
if KeepLog then writeln(Outfile,Line)
else if Keep then writeln(KeepFile,Line);
end;
close(Infile);
close(Outfile);
erase(Infile);
rename(Outfile,LogName);
if Keep then close(KeepFile);
end.